package beanstao.util.type.base;

import java.lang.reflect.Array;
import java.util.Map;

import beanstao.util.Util;
import beanstao.util.exception.technical.util.reflect.FailToCastObjectException;
import beanstao.util.type.Castor;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class Array2Map extends Castor<Object, Map>
{

	public Array2Map()
	{
		fromClass = Array.class;
		toClass = Map.class;
	}

	@Override
	public Map cast(Object src, Class<?> toType, String... args) throws FailToCastObjectException
	{
		if ((null == args) || (args.length == 0))
			throw Util.makeThrow(FailToCastObjectException.class, "For the elements in array %s[], castors don't know which one is the key field.", src.getClass().getComponentType().getName());
		return Util.array2map((Class<Map<Object, Object>>) toType, src, args[0]);
	}

}
